home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
HYPERCAR
/
SYSENV__
/
SYSENVIR.C
next >
Wrap
Text File
|
1988-11-24
|
7KB
|
295 lines
/* SysEnvirons.c */
/* SysEnvirons XFCN for HyperCard
with LightSpeedC v. 3.01 - 11/22/88
Copyright 1988 by
Implements Macintosh SysEnvirons stuff Sam Thornton
PO Box 123
See SysEnvirons.docs for user interface Fairfield NE 68938
Some portions Copyright
by Symantec and Apple.
NOTE: All 'StringPtr' types in Compuserve: 71750,667
HyperXCmd.h and glue should GEnie: S.THORNTON5
be dereferenced to type 'Ptr'
for this to compile properly. May be copied and
distributed for personal
use without charge only,
except for nominal
distribution fees. For
commercial use or
distribution, contact
author, above. */
#include "HyperXCmd.h"
#include "SetUpA4.h"
#include "MemoryMgr.h"
#include "MacTypes.h"
#include "unix.h"
#include "FileMgr.h"
#include "DeviceMgr.h"
#include "OSUtil.h"
#include "strings.h"
/* some constants for attribute requests */
#define APPLETALK 1
#define COLORQUICKDRAW 2
#define FPU 3
#define KEYBOARD 4
#define MACHINE 5
#define MEMORY 6
#define PROCESSOR 7
#define SYSTEM 8
#define VERSION 9
/* keyword list for requests we recognize */
typedef struct _k {
char _word[15];
} _k;
_k _key[] = {
"appletalk",
"colorquickdraw",
"fpu",
"keyboard",
"machine",
"memory",
"processor",
"system",
"version",
};
typedef struct trade_mark {
char mk[90];
} trade_mark;
trade_mark mrk = {" SysEnvirons XFCN Copyright 1988 by Sam Thornton * PO Box 123 * Fairfield NE 68938 "};
pascal void main (paramPtr)
XCmdBlockPtr paramPtr;
{
int length;
Handle answer;
char temp_string[32];
SysEnvRec environment;
Str255 my_machine;
RememberA0();
SetUpA4();
/* if no keyword or keyword too long, then abort */
if (paramPtr->paramCount != 1 || strlen(*paramPtr->params[0]) > 30) goto PANIC;
/* keyword eval... */
length = lookup(paramPtr);
/* if the keyword is not recognized, then abort */
if (length == 0) goto PANIC;
SysEnvirons(99,&environment); /* use a large v.num for force current */
switch(length) {
case VERSION: /* SysEnvirons version number request */
stci_d(my_machine, environment.environsVersion);
break;
case MACHINE: /* Mac Model request */
switch(environment.machineType) {
case envMachUnknown:
strcpy(my_machine, "Unknown");
break;
case env512KE:
strcpy(my_machine,"Macintosh 512KE");
break;
case envMacPlus:
strcpy(my_machine,"Macintosh Plus");
break;
case envSE:
strcpy(my_machine,"Macintosh SE");
break;
case envMacII:
strcpy(my_machine,"Macintosh II");
break;
case envMac:
strcpy(my_machine,"Macintosh 64K");
break;
case envXL:
strcpy(my_machine,"Macintosh XL");
break;
default:
strcpy(my_machine, "Unknown");
break;
} /* END MACHINE SWITCH */
break;
case SYSTEM: /* System version request */
switch(environment.systemVersion) {
case 0:
strcpy(my_machine, "Unknown");
break;
default:
stci_d(temp_string, (environment.systemVersion & 0xFF00) >> 0x0008, 9);
strcpy(my_machine, temp_string);
strcat(my_machine, ".");
stci_d(temp_string, (environment.systemVersion & 0x00F0) >> 0x0004, 9);
strcat(my_machine, temp_string);
if (environment.systemVersion & 0x000F) {
strcat(my_machine, ".");
stci_d(temp_string, environment.systemVersion & 0x000F, 9);
strcat(my_machine, temp_string);
}
break;
} /* END SYSTEM SWITCH */
break;
case PROCESSOR: /* Processor type request */
switch(environment.processor) {
case envCPUUnknown:
strcpy(my_machine, "Unknown");
break;
case env68000:
strcpy(my_machine,"68000");
break;
case env68010:
strcpy(my_machine,"68010");
break;
case env68020:
strcpy(my_machine,"68020");
break;
default:
strcpy(my_machine, "Unknown");
break;
} /* END PROCESSOR SWITCH */
break;
case FPU: /* FPU present request */
if (environment.hasFPU)
strcpy(my_machine,"installed");
else strcpy(my_machine,"not installed");
break;
case COLORQUICKDRAW: /* ColorQD present request */
if (environment.hasColorQD)
strcpy(my_machine, "installed");
else strcpy(my_machine,"not installed");
break;
case KEYBOARD: /* Model keyboard installed request */
switch(environment.keyBoardType) {
case envUnknownKbd:
strcpy(my_machine, "Macintosh Plus Keyboard with keypad"); /* Looks screwy, but that╒s what Inside Mac sez */
break;
case envMacKbd:
strcpy(my_machine, "Macintosh Keyboard");
break;
case envMacAndPad:
strcpy(my_machine, "Macintosh Keyboard with keypad");
break;
case envMacPlusKbd:
strcpy(my_machine, "Macintosh Plus Keyboard");
break;
case envAExtendKbd:
strcpy(my_machine, "Apple Extended Keyboard");
break;
case envStandADBKbd:
strcpy(my_machine, "ADB Keyboard");
break;
default:
strcpy(my_machine, "Unknown");
break;
} /* END KEYBOARD SWITCH */
break;
case APPLETALK: /* Appletalk version request */
switch(environment.atDrvrVersNum) {
case 0:
strcpy(my_machine, "not installed");
break;
default:
stci_d(temp_string, (environment.atDrvrVersNum & 0x0FF0) >> 0x0004, 9);
strcpy(my_machine, temp_string);
strcat(my_machine, ".");
stci_d(temp_string, (environment.atDrvrVersNum & 0x000F), 9);
strcat(my_machine, temp_string);
break;
} /* END APPLETALK SWITCH */
break;
case MEMORY: /* Installed memory size request */
NumToString(MemTop, &temp_string);
PtoCstr(temp_string);
strcat(temp_string, " / 1024");
CtoPstr(temp_string);
answer = EvalExpr(paramPtr, temp_string);
strcpy(my_machine, *answer);
DisposHandle(answer);
break;
default:
break;
} /* END OF MAIN SWITCH */
length = strlen(my_machine);
if (length > 0) { /* we're bulletproof here */
paramPtr->returnValue = NewHandle(length + 1);
strcpy(*paramPtr->returnValue, my_machine);
goto NOPANIC;
}
PANIC:
SysBeep(1);
NOPANIC:
RestoreA4();
return;
}
/* lookup routine - mod from CAPPS Toolbox lookup */
lookup(paramPtr)
XCmdBlockPtr paramPtr;
{
register long i, j, x, last;
register int dir;
char temp_string[31];
strcpy(temp_string, (*paramPtr->params[0]));
dir = strlen(temp_string);
for (; dir >= 0; dir--)
temp_string[dir] = tolower(temp_string[dir]);
last = (sizeof(_key) / sizeof(struct _k)) - 1;
for (i = 0, j = last; i <= j; ){
x = (i + j) >> 1;
dir = strcmp(temp_string, &_key[x]._word[0]);
if (dir < 0)
j = x - 1;
else if (dir > 0)
i = x + 1;
else
return(x + 1);
}
return 0;
}